<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui"
	xmlns:ui="http://java.sun.com/jsf/facelets">

<h:head>Add a new employee</h:head>
<body>
	<ui:composition template="/Template/TemplateAdmin.xhtml">
		<ui:define name="AdminContent">
			<h:form id="form"><p:panelGrid columns="1">
					<p:selectOneMenu value="#{addEmployeeView.visibilityFragment}"
						onchange="#{addEmployeeView.instaceEmployee()}">
						<f:selectItem itemLabel="Commissioned" itemValue="Commissioned"  />
						<f:selectItem itemLabel="Salaried" itemValue="Salaried"
							noSelectionOption="true" />
						<f:selectItem itemLabel="Contractor" itemValue="Contractor"  />
						 <f:ajax render="@form"/>
					</p:selectOneMenu>
				</p:panelGrid>
				
				<h:panelGroup id="data">
				<p:panelGrid>
					<p:row>
						<p:column>
							<p:outputLabel value="Code" />
						</p:column>
						<p:column>
							<p:inputText id="code"
								value="#{addEmployeeView.employee.codfisc}" required="true" />
						</p:column>
						<p:column>
							<p:message for="code" />
						</p:column>
					</p:row>
					<p:row>
						<p:column>
							<p:outputLabel value="Name" />
						</p:column>
						<p:column>
							<p:inputText id="name" value="#{addEmployeeView.employee.name}"
								required="true" />
						</p:column>
						<p:column>
							<p:message for="name" />
						</p:column>
					</p:row>
					<p:row>
						<p:column>
							<p:outputLabel value="Surname" />
						</p:column>
						<p:column>
							<p:inputText id="surname"
								value="#{addEmployeeView.employee.surname}" required="true" />
						</p:column>
						<p:column>
							<p:message for="surname" />
						</p:column>
					</p:row>
					
					<p:row>
						<p:column>
							<p:outputLabel value="Username" />
						</p:column>
						<p:column>
							<p:inputText id="username"
								value="#{addEmployeeView.employee.username}" required="true">
								<f:validateLength minimum="5" maximum="10" />
							</p:inputText>
						</p:column>
						<p:column>
							<p:message for="username" />
						</p:column>
					</p:row>
					<p:row>
						<p:column>
							<p:outputLabel value="Password" />
						</p:column>
						<p:column>
							<p:inputText id="password" value="#{addEmployeeView.employee.password}" ><f:validateLength minimum="5" maximum="10" /></p:inputText>
						</p:column>
						<p:column>
							<p:message for="password" />
						</p:column>
					</p:row>
				</p:panelGrid>
				<p:panelGrid columns="1">
					<p:outputLabel value="Type of Paymethod" />
					<p:selectOneMenu value="#{addEmployeeView.visibFragment3}"
						onchange="#{addEmployeeView.instancePayMethod()}">
						<f:selectItem itemLabel="Cash on office" itemValue="" />
						<f:selectItem itemLabel="Bank" itemValue="BankPayMethod" />
						<f:selectItem itemLabel="SendMail" itemValue="SendMailPayMethod" />
						 <f:ajax render="@form"/>
					</p:selectOneMenu>
				</p:panelGrid>
				<p:panelGrid>
					<ui:fragment id="BankPayMethod"
						rendered="#{addEmployeeView.employee.payMethod.getClass().getSimpleName() eq  'BankPayMethod'}">
						<p:row>
							<p:column>
								<p:outputLabel value="Iban" />
							</p:column>
							<p:column>
								<p:inputText id="iban" binding="#{iban}"
									valueChangeListener="#{addEmployeeView.setIban(iban.value)}" ></p:inputText>
							</p:column>
							<p:column>
								<p:message for="iban"></p:message>
							</p:column>
						</p:row>
					</ui:fragment>
					<ui:fragment id="SendMailPayMethod"
						rendered="#{addEmployeeView.employee.payMethod.getClass().getSimpleName() eq  'SendMailPayMethod'}">
						<p:row>
							<p:column>
								<p:outputLabel value="address" />
							</p:column>
							<p:column>
								<p:inputText id="address" binding="#{address}"
									valueChangeListener="#{addEmployeeView.setAddress(address.value)}" ></p:inputText>
							</p:column>
							<p:column>
								<p:message for="address"></p:message>
							</p:column>
						</p:row>
					</ui:fragment>
					</p:panelGrid>
				
				<p:panelGrid columns="1">
					<p:outputLabel value="Type of Association" />
					<p:selectOneMenu value="#{addEmployeeView.visibFragment2}"
						onchange="#{addEmployeeView.instanceAssociation()}">
						<f:selectItem itemLabel="No Association" itemValue="" />
						<f:selectItem itemLabel="Associated" itemValue="Union" />
						 <f:ajax render="@form"/>
					</p:selectOneMenu>
				</p:panelGrid>
				
				
				<p:panelGrid>
					<ui:fragment id="association"
						rendered="#{addEmployeeView.employee.getAssociation().getClass().getSimpleName() eq  'Union'}">
						<p:row>
							<p:column>
								<p:outputLabel value="Union tax" />
							</p:column>
							<p:column>
								<p:inputText id="tax" value="0.0" binding="#{union_tax}"
									valueChangeListener="#{addEmployeeView.setUnionTax(union_tax.value)}" ><f:validateDoubleRange minimum="0"></f:validateDoubleRange></p:inputText>
							</p:column>
							<p:column>
								<p:message for="tax"></p:message>
							</p:column>
						</p:row>
					</ui:fragment>
					<ui:fragment
						rendered="#{addEmployeeView.employee.getClass().getSimpleName() eq 'Salaried' ||addEmployeeView.employee.getClass().getSimpleName() eq 'Commissioned' }">
						<p:row>
							<p:column>
								<p:outputLabel value="Monthly salary" />
							</p:column>
							<p:column>
								<p:inputText id="salary" binding="#{salary}" value="0.0"
									valueChangeListener="#{addEmployeeView.MonthlySalary(salary.value)}" ><f:validateDoubleRange minimum="0"></f:validateDoubleRange></p:inputText>
							</p:column>
							<p:column>
								<p:message for="salary"></p:message>
							</p:column>
						</p:row>
					</ui:fragment>
					<ui:fragment
						rendered="#{addEmployeeView.employee.getClass().getSimpleName() eq 'Commissioned'}">
						<p:row>
							<p:column>
								<p:outputLabel value="Sales percent" />
							</p:column>
							<p:column>
								<p:inputText id="percent" binding="#{sales}" value="0.0"
									valueChangeListener="#{addEmployeeView.SalesPercent(sales.value)}" ><f:validateDoubleRange minimum="0"></f:validateDoubleRange></p:inputText>
							</p:column>
							<p:column>
								<p:message for="percent"></p:message>
							</p:column>
						</p:row>
					</ui:fragment>

					<ui:fragment
						rendered="#{addEmployeeView.employee.getClass().getSimpleName() eq 'Contractor' }">
						<p:row>
							<p:column>
								<p:outputLabel value="Hourly rate" />
							</p:column>
							<p:column>
								<p:inputText id="rate" binding="#{rate}" value="0.0"
									valueChangeListener="#{addEmployeeView.HourlyRate(rate.value)}" ><f:validateDoubleRange minimum="0"></f:validateDoubleRange></p:inputText>
							</p:column>
							<p:column>
								<p:message for="rate"></p:message>
							</p:column>
						</p:row>
					</ui:fragment>


					<p:row>
						<p:column colspan="2">
							<p:dialog header="Add employee" widgetVar="dialogYes"
								minHeight="40">
								<p:panelGrid columns="1">
									<h:outputText value="Dati Aggiunti" />
									<p:button value="Ok" outcome="employeeList"></p:button>
								</p:panelGrid>
							</p:dialog>
							<p:dialog header="Add Employee" widgetVar="dialogNo"
								minHeight="40">
								<p:panelGrid columns="1">
									<h:outputText value="#{addEmployeeView.message}" />
								</p:panelGrid>
							</p:dialog>
							<p:commandButton action="#{addEmployeeView.addNewEmployee()}"
								value="Add Employee" update="data" />
						</p:column>
					</p:row>
				</p:panelGrid>
				</h:panelGroup>
			</h:form>
		</ui:define>
	</ui:composition>
</body>
</html>
